<!DOCTYPE html>
<html lang="en">

<head>
    <title>类式继承</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
</head>

<body>
    <script>
        var Book = (function () {
            //静态私用变量
            var bookNum = 0;
            //静态私有方法
            function checkBook(name) {

            }
            //创建类
            function _book(newId, newName, newPrice) {
                //私有变量
                var name, price;
                //私有方法
                function chekcID(id) {}
                //特权方法
                this.getName = function () {};
                this.getPrice = function () {};
                this.setName = function () {};
                this.setPrice = function () {};
                //公有属性
                this.id = newId;
                //公有方法
                this.copy = function () {};
                bookNum++;
                if (bookNum > 100) {
                    throw new Error('我们仅出版100本书');
                }
                //构造器
                this.setName(name);
                this.setPrice(price);
            }
            //构造原型
            _book.prototype = {
                //静态属性方法
                isJSBook: false,
                //静态公有方法
                display: function () {}
            };
            //返回类
            return _book;
        })();

        var Book2 = function (title, time, type) {
            if (this instanceof Book) {
                this.title = title;
                this.time = time;
                this.type = type;
            } else {
                return new Book(title, time, type);
            }
        }
        var book2 = Book('javascript', 2014, 'js');

        //继承
        /** 类似继承**/
        function SuperClass() {
            this.superValue = true;
        }
        //为父类添加公有方法
        SuperClass.prototype.getSuperValue = function () {
            return this.superValue;
        };
        //声明子类
        function SubClass() {
            this.subClass = false;
        }
        //继承父类
        SubClass.prototype = new SubClass();
        //为子类添加公有方法
        SubClass.prototype.getSubValue = function () {
            return this.getSubValue;
        };
        var instance=new SubClass();
        console.log(intance.getSuperValue());
        console.log(instance.getSubValue());
        console.log(instance instanceof SubClass);
        console.log(instance instanceof SuperClass);
        console.log(SubClass.prototype instanceof SuperClass);
        //Object就是素有对象的祖先了
        console.log(instance instanceof Object);

        //

    </script>
</body>

</html>